#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int > vec;
typedef pair < int , int > pii;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 1e4 + 10;

int n;
ll f[N << 1], a[N];

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
	n = in; rep(i, 1, n - 1) a[i] = in;
	memset(f, 0xcf, sizeof f); f[0] = a[1] * n;
	int tot = n - 1; tot <<= 1; tot -= n; 
	rep(i, 1, n - 1) {
		rep(j, i, tot) f[j] = max(f[j], f[j - i] + a[i + 1] - a[1]);
	}
	cout << f[tot] << endl;
}
